import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入数组的长度: ");
        int n = scanner.nextInt();

        int[] array = new int[n];

        System.out.println("请输入" + n + "个整数：");
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }
        System.out.println("数组中子数组之和的最大值为："+maxSum(array));
    }
        public static int maxSum(int[] nums) {
            if (nums == null || nums.length == 0) {
                return 0;
            }

            int max1 = nums[0]; // 当前最大和
            int max2 = nums[0]; // 以当前元素为结尾的最大子数组和

            for (int i = 1; i < nums.length; i++) {
                max2 = Math.max(nums[i], max2 + nums[i]);
                max1 = Math.max(max1, max2);
            }
            return max1;
        }
}
